﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using oLGame.Game;
using oLGame.Game.Players;
using oLGame.Game.Items;
using oLGame.Game.Items.Weapons;
using oLGame.Game.World;
namespace oLGame
{
    class Program
    {
        static void Logger(string s)
        {
            Console.WriteLine(s);
        }

        static void Action(BaseSystemAction action)
        {
            // Console.WriteLine(action.GetType() + " was triggered.");
        }

        static void Main(string[] args)
        {
            // Trying to work out the best way to do events. What we want is the ability to have events for each action that way it can handle
            // The networking code and basically the game mechanics.

            BaseSystemAction.Log += new BaseSystemAction.LogHandler(Logger);
            Engine.Action += new Engine.ActionHandler(Action);

            Console.WriteLine("oLGame Engine: Started.");
            Console.WriteLine("A collaboration by okaygo and Link.");

            Player player1 = new Player(100.00, 100.00, 100.00);
            Player player2 = new Player(100.00, 100.00, 100.00);
            Player player3 = new Player(300.00, 100.00, 100.00);
            Room mainRoom = new Room();
            Axe pickupItem = new Axe();
            
            pickupItem.CurrentRoom = mainRoom;
            player1.Name = "Scott";
            player2.Name = "Dan";
            mainRoom.Name = "Skype Conference";
            player1.CurrentRoom = mainRoom;
            player2.CurrentRoom = mainRoom;

            foreach( Player p in player1.CurrentRoom.Players)
                Console.WriteLine(p.Name);
            foreach (Item i in player1.CurrentRoom.Items)
                Console.WriteLine(i.Name);
            // This generates a new Axe/Club for our players, but since there is no backpack to hold items then this is currently the only way.
            // Eventually there needs to be an action for this.
            player2.Weapon = new Axe();
            player1.Weapon = new Club();
            Engine.Running = true;
            while (Engine.Running)
            {
                Engine.Tick();
                if (player3.IsDead())
                    Engine.Running = false;

                // We need to have a server running that can handle incoming connections then the client will send commands to the server, 
                // perhaps the server should listen on port 80 since we are talking about making a web game using XML.

                player1.Attack(player3);
                player2.Attack(player3);


            }
            Console.WriteLine("oLGame Engine: Stopped.");

            Console.WriteLine(player1.IsDead() ? player1.Name + " is dead" : player1.Name + " is alive.");
            Console.WriteLine(player2.IsDead() ? player2.Name + " is dead" : player2.Name + " is alive.");

            Console.ReadKey();

        }
    }
}
